#ifndef THINK_THINK_DB_CONNECTOR_MYSQL_H
#define THINK_THINK_DB_CONNECTOR_MYSQL_H

static char* think_db_connector_mysql =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think\\db\\connector;\n"
	"\n"
	"use PDO;\n"
	"use think\\db\\Connection;\n"
	"use think\\Log;\n"
	"\n"
	"/**\n"
	" * mysql数据库驱动\n"
	" */\n"
	"class Mysql extends Connection\n"
	"{\n"
	"\n"
	"    protected $builder = \'\\\\think\\\\db\\\\builder\\\\Mysql\';\n"
	"\n"
	"    /**\n"
	"     * 解析pdo连接的dsn信息\n"
	"     * @access protected\n"
	"     * @param array $config 连接信息\n"
	"     * @return string\n"
	"     */\n"
	"    protected function parseDsn($config)\n"
	"    {\n"
	"        if (!empty($config[\'socket\'])) {\n"
	"            $dsn = \'mysql:unix_socket=\' . $config[\'socket\'];\n"
	"        } elseif (!empty($config[\'hostport\'])) {\n"
	"            $dsn = \'mysql:host=\' . $config[\'hostname\'] . \';port=\' . $config[\'hostport\'];\n"
	"        } else {\n"
	"            $dsn = \'mysql:host=\' . $config[\'hostname\'];\n"
	"        }\n"
	"        $dsn .= \';dbname=\' . $config[\'database\'];\n"
	"\n"
	"        if (!empty($config[\'charset\'])) {\n"
	"            $dsn .= \';charset=\' . $config[\'charset\'];\n"
	"        }\n"
	"        return $dsn;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 取得数据表的字段信息\n"
	"     * @access public\n"
	"     * @param string $tableName\n"
	"     * @return array\n"
	"     */\n"
	"    public function getFields($tableName)\n"
	"    {\n"
	"        list($tableName) = explode(\' \', $tableName);\n"
	"        if (false === strpos($tableName, \'`\')) {\n"
	"            if (strpos($tableName, \'.\')) {\n"
	"                $tableName = str_replace(\'.\', \'`.`\', $tableName);\n"
	"            }\n"
	"            $tableName = \'`\' . $tableName . \'`\';\n"
	"        }\n"
	"        $sql    = \'SHOW COLUMNS FROM \' . $tableName;\n"
	"        $pdo    = $this->query($sql, [], false, true);\n"
	"        $result = $pdo->fetchAll(PDO::FETCH_ASSOC);\n"
	"        $info   = [];\n"
	"        if ($result) {\n"
	"            foreach ($result as $key => $val) {\n"
	"                $val                 = array_change_key_case($val);\n"
	"                $info[$val[\'field\']] = [\n"
	"                    \'name\'    => $val[\'field\'],\n"
	"                    \'type\'    => $val[\'type\'],\n"
	"                    \'notnull\' => (bool) (\'\' === $val[\'null\']), // not null is empty, null is yes\n"
	"                    \'default\' => $val[\'default\'],\n"
	"                    \'primary\' => (strtolower($val[\'key\']) == \'pri\'),\n"
	"                    \'autoinc\' => (strtolower($val[\'extra\']) == \'auto_increment\'),\n"
	"                ];\n"
	"            }\n"
	"        }\n"
	"        return $this->fieldCase($info);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 取得数据库的表信息\n"
	"     * @access public\n"
	"     * @param string $dbName\n"
	"     * @return array\n"
	"     */\n"
	"    public function getTables($dbName = \'\')\n"
	"    {\n"
	"        $sql    = !empty($dbName) ? \'SHOW TABLES FROM \' . $dbName : \'SHOW TABLES \';\n"
	"        $pdo    = $this->query($sql, [], false, true);\n"
	"        $result = $pdo->fetchAll(PDO::FETCH_ASSOC);\n"
	"        $info   = [];\n"
	"        foreach ($result as $key => $val) {\n"
	"            $info[$key] = current($val);\n"
	"        }\n"
	"        return $info;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * SQL性能分析\n"
	"     * @access protected\n"
	"     * @param string $sql\n"
	"     * @return array\n"
	"     */\n"
	"    protected function getExplain($sql)\n"
	"    {\n"
	"        $pdo    = $this->linkID->query(\"EXPLAIN \" . $sql);\n"
	"        $result = $pdo->fetch(PDO::FETCH_ASSOC);\n"
	"        $result = array_change_key_case($result);\n"
	"        if (isset($result[\'extra\'])) {\n"
	"            if (strpos($result[\'extra\'], \'filesort\') || strpos($result[\'extra\'], \'temporary\')) {\n"
	"                Log::record(\'SQL:\' . $this->queryStr . \'[\' . $result[\'extra\'] . \']\', \'warn\');\n"
	"            }\n"
	"        }\n"
	"        return $result;\n"
	"    }\n"
	"\n"
	"    protected function supportSavepoint()\n"
	"    {\n"
	"        return true;\n"
	"    }\n"
	"\n"
	"}\n"
	"\n"
;
#endif